#/bin/bash
set -e

ROOT_DIR=$(cd `dirname $0`/..; pwd)
cd ${ROOT_DIR}

pnpm install
pnpm run docs:build

cd dist

# 如果是发布到自定义域名
# echo 'haijunit.top' > CNAME

if [ -z "$GITHUB_TOKEN" ]; then
  msg='deploy'
  githubUrl=git@github.com:zhanghaijun666/zhanghaijun666.github.io.git
else
  msg='来自github actions的自动部署'
  githubUrl=https://zhanghaijun666:${GITHUB_TOKEN}@github.com/zhanghaijun666/zhanghaijun666.github.io.git
  git config --global user.name "zhanghaijun666"
  git config --global user.email "zhanghaijun_java@163.com"
fi
echo "${githubUrl}"
git init

git add -A
git commit -m "${msg}"
git push --force --quiet ${githubUrl} master
